package pathfinding
{

	public class quicksort
	{
		public static function sort(arrayInput:Vector.<Portal>, left:int, right:int):Vector.<Portal>
		{
			var i:int = left;
			var j:int = right;
			var srodkowy:Portal = arrayInput[Math.round((left+right)*.5)];
			
			
			while (i<=j)
			{
				while (arrayInput[i].F < srodkowy.F)
				{
					i++;
				}
				while (arrayInput[j].F > srodkowy.F)
				{
					j--;
				}
				if (i <= j)
				{
					var tempStore:Portal = arrayInput[i];
					arrayInput[i] = arrayInput[j];
					i++;
					arrayInput[j] = tempStore;
					j--;
				}
			}
			
			if (left < j)
			{
				sort(arrayInput, left, j);
			}
			if (i < right)
			{
				sort(arrayInput, i, right);
			}
			
			return arrayInput;
		}
	}
}